<?php

// 本类由系统自动生成，仅供测试用途
class IndexAction extends CommonAction {

    public function index() {

        $this->assign('pagetitle', 'Splio');
        $this->display();
    }

    public function show() {
        $my_info = session('my_info');

        $map = array();
        $map['enable'] = 1;
        if($my_info['role'] > 1) {
            $map['group'] = $my_info['group'];
        }

    	$regM = M('ispreg');
        $rawRegs = $regM->where($map)->select();

    	$this->assign('rawRegs', $rawRegs);
    	$this->assign('pagetitle', 'Splio | Show');
    	$this->assign('ispShowActive', 'active');
    	
    	$this->display();
    }

    public function insert() {

        $rawGroups = A('Group')->getAll();

        $this->assign('regGroup', $rawGroups);
    	$this->assign('pagetitle', 'Splio | Insert');
    	$this->assign('ispInsertActive', 'active');
    	
    	$this->display();
    }

    public function update() {

    	$regM = M('ispreg');
    	$rawRegs = $regM->where("enable=1")->select();

        $rawGroups = A('Group')->getAll();
        
        $this->assign('regGroup', $rawGroups);
    	$this->assign('rawRegs', $rawRegs);
    	$this->assign('pagetitle', 'Splio | Update');
    	$this->assign('ispUpdateActive', 'active');
    	
    	$this->display();
    }

    public function trash() {

        $regM = M('ispreg');
        $rawRegs = $regM->where("enable=0")->select();

        $this->assign('rawRegs', $rawRegs);
        $this->assign('pagetitle', 'Splio | Deleted');
        $this->assign('ispTrashActive', 'active');
        
        $this->display();
    }



    public function doinsert() {
    	
    	$formData = $_POST;

    	$regM = M('ispreg');

    	$regM -> add($formData);

        $this->redirect('Index/insert');
    }


    public function doupdate() {

        $formData = $_POST;

        $id = array_shift($formData);
        
        $regM = M('ispreg');

        $result = $regM -> where("id=$id") -> save($formData);

        echo $result;
    }


    public function dodelete() {

        $formData = $_POST;

        $id = array_shift($formData);

        $formData['enable'] = 0;

        $regM = M('ispreg');

        $result = $regM -> where("id=$id") -> save($formData);

        echo $result;
    }


    public function doresume() {

     $formData = $_POST;

        $id = array_shift($formData);

        $formData['enable'] = 1;

        $regM = M('ispreg');

        $result = $regM -> where("id=$id") -> save($formData);

        echo $result;   
    }

}